package com.example.fraction.slice;

import com.example.fraction.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.ability.fraction.FractionScheduler;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.TabList;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {
    TabList tabList;
    TabList.Tab tabList_tab;
    String[] s={"头条","新闻","财经"};
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        Fraction fraction =new Fraction();
        tabList = (TabList) findComponentById(ResourceTable.Id_tablist);
        for (int i=0;i<s.length;i++){
            tabList_tab=tabList.new Tab(this);
            tabList_tab.setText(s[i]);
            tabList.addTab(tabList_tab);
            if (s[i].equals("头条")){
                tabList_tab.select();
                ((FractionAbility)getAbility()).getFractionManager()
                        .startFractionScheduler()
                        .replace(ResourceTable.Id_xianshi,new TestFraction())
                        .submit();
            }
        }
        tabList.addTabSelectedListener(new TabList.TabSelectedListener() {
            @Override
            public void onSelected(TabList.Tab tab) {
                int i=tab.getPosition();
                if (i==0){
                    ((FractionAbility)getAbility()).getFractionManager()
                            .startFractionScheduler()
                            .replace(ResourceTable.Id_xianshi,new TestFraction())
                            .submit();
                }
                if (i==1){
                    ((FractionAbility)getAbility()).getFractionManager()
                            .startFractionScheduler()
                            .replace(ResourceTable.Id_xianshi,new Test_new())
                            .submit();
                }
                if (i==2){
                    ((FractionAbility)getAbility()).getFractionManager()
                            .startFractionScheduler()
                            .replace(ResourceTable.Id_xianshi,new Test_caijin())
                            .submit();
                }
            }

            @Override
            public void onUnselected(TabList.Tab tab) {

            }

            @Override
            public void onReselected(TabList.Tab tab) {

            }
        });

    }
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
